<?php
/**
 * Description of _form_biz_frontend
 * 
 * @author trongkhoi
 * @since Nov 7, 2013 - 6:42:00 PM
 */
?>
<style>
    .checker{
        float: left
    }
    div.checker{
        margin-top: 0!important;
    }
</style>
<link type="text/css"  rel="stylesheet" href="<?php echo $this->assetDirWeb ?>css/Webmaster/schedules.css">
<link href="<?php echo $this->assetDirWeb ?>css/bootstrap-timepicker.min.css" rel="stylesheet">
<hr>
<?php $model     = $biz->business ? $biz->business : new Business(); ?>
<?php $work_date = unserialize($model->work_day); ?>
<form method="POST" class="form-horizontal">

    <div class="control-group">
        <h3><label class="control-label" for="Business_biz_url"><?php echo $model->getAttributeLabel('biz_url') ?></label></h3>
        <span class="muted">The profile page will be displayed as www.Webmaster.com.sg/<strong>SHOPNAME</strong>
            (e.g. <strong>http://Webmaster.com.sg/SelectiveFitness</strong>)</span>
        <div class ="controls">
            <?php
            echo CHtml::textField('Business[biz_url]', $model->biz_url, array(
                'placeholder' => $model->getAttributeLabel('biz_url'),
                'class'       => 'input-file uniform_on input-reset',
            ));
            ?>
        </div>
    </div>
    <div class="control-group">
        <h3><label class="control-label" for="Business_is_staff">Profile owner performs services</label></h3>
        <div class="controls">
            <?php
            $check     = ($model->is_staff == 1) ? TRUE : FALSE;
            echo CHtml::checkBox('Business[is_staff]', $check, array(
                'placeholder' => $model->getAttributeLabel('is_staff'),
                'class'       => 'input-file uniform_on input-reset',
            ));
            ?>
        </div>
    </div>
    <?php if ($this->isAdmin): ?>
        <div class="control-group">
            <h3><label class="control-label" for="Business_is_pos"><?php echo $model->getAttributeLabel('is_pos') ?></label></h3>
            <div class ="controls">
                <?php
                echo CHtml::radioButtonList('Business[is_pos]', $model->is_pos, Business::getPOSArray(), array(
                    'template' => '<label class="radio">{input} {label}</label>'
                ));
                ?>
            </div>
        </div>
    <?php endif; ?>

    <div class="control-group">
        <h3><label for="Business_is_pos"><?php echo $model->getAttributeLabel('open_time') ?></label></h3>
        <?php $open_time  = $model->open_time ? Utils::convertSecondToTime($model->open_time) : NULL; ?>
        <!--<div class ="controls">-->
            <!--<input type="number" name="OpenTime[days]" value="<?php // echo $open_time['days']              ?>">&nbsp;days-->
        <i>Advance Booking Online (minimum) - Customers must book at least</i>
        &nbsp;<input type="number" class="span1" name="OpenTime[hours]" value="<?php echo $open_time['hours'] ?>">&nbsp;hours
        <input type="number" class="span1" name="OpenTime[mins]" value="<?php echo $open_time['mins'] ?>">&nbsp;minutes&nbsp;<i>in advance</i>

        <!--</div>-->
    </div>
    <div class="control-group">
        <h3><label for="Business_is_pos"><?php echo $model->getAttributeLabel('close_time') ?></label></h3>
        <?php $close_time = $model->close_time ? Utils::convertSecondToTime($model->close_time) : NULL; ?>
        <!--<div class ="controls">-->
        <i>Advance Booking Online (maximum) - Customers cannot book  more than </i>
        &nbsp;<input type="number" class="span1" name="CloseTime[days]" value="<?php echo $close_time['days'] ?>">&nbsp;days
        <input type="number" class="span1" name="CloseTime[hours]" value="<?php echo $close_time['hours'] ?>">&nbsp;hours
        <input type="number" class="span1" name="CloseTime[mins]" value="<?php echo $close_time['mins'] ?>">&nbsp;minutes&nbsp;<i>in advance</i>
        <!--</div>-->
    </div>
    <div class="table-responsive"> 
        <table class="table table-bordered table-striped">
            <tr>
                <th class="center"><?php echo $model->getAttributeLabel('work_day') ?></th>
                <th class="center">Time Of Day</th>
                <th class="center">Start Time</th>
                <th class="center">End Time</th>
                <th class="center"></th>
            </tr>
            <?php foreach (Business::getDateArray() as $i => $date): ?>
                <tr>
                    <td class="center">
                        <input id="Date_<?php echo $i ?>_checkbox" type="checkbox" name="WorkDay[]"
                               value="<?php echo $date ?>" <?php echo Business::checkAddedDate($work_date, $date) ? 'checked' : '' ?>/>
                        <label for="<?php echo $date ?>"><?php echo $date ?></label>
                    </td>

                    <td>
                        <?php foreach (Business::getDayArray() as $day): ?>
                            <?php echo $day ?><br>
                        <?php endforeach; ?>
                    </td>

                    <td class="bootstrap-timepicker">
                        <?php foreach (Business::getDayArray() as $day): ?>
                            <input id="Date_<?php echo $i ?>_<?php echo $day ?>_start" class="input input-number input-time span10" type="text" style="margin-bottom: 0 !important;"
                                   name="Date[<?php echo $date ?>][<?php echo $day ?>][]"  placeholder="hh:mm"
                                   value="<?php echo isset($work_date[$date][$day][0]) ? $work_date[$date][$day][0] : ''; ?>"/>
                            <br>
                        <?php endforeach; ?>
                    </td>

                    <td class="bootstrap-timepicker">
                        <?php foreach (Business::getDayArray() as $day): ?>
                            <input id="Date_<?php echo $i ?>_<?php echo $day ?>_end" class="input input-number input-time span10" type="text" style="margin-bottom: 0 !important;"
                                   name="Date[<?php echo $date ?>][<?php echo $day ?>][]"  placeholder="hh:mm"
                                   value="<?php echo isset($work_date[$date][$day][1]) ? $work_date[$date][$day][1] : ''; ?>"/>
                            <br>
                        <?php endforeach; ?>
                    </td>
                    <td class="center">
                        <?php if ($i != 0): ?>
                            <a title="Copy Previous Day" class="btn btn-primary btn-lg" href="#" onclick="copy_previous_day(<?php echo $i ?>);"><i class="icon-copy"></i></a>
                        <?php endif; ?>
                    </td>
                </tr>
            <?php endforeach; ?>
        </table>
    </div>
    <div class="control-group">
        <h3><?php echo $model->getAttributeLabel('book_bg') ?></h3>&nbsp;
        <span class="muted">Recommended resolution: 1302px X 430px</span>
        <div class ="controls">
            <div style="margin-bottom: 10px">
                <img src="<?php echo $model->bookBG ?>" style="max-width: 800px" alt="BookingPage Background">
            </div>
            <input type="file" name="book_bg"/>
        </div>
    </div>
    <div class="control-group">
        <h3><label class="control-label" for="slider_type"><?php echo $model->getAttributeLabel('slider_type') ?></label></h3>
        <div class ="controls">
            <?php
            echo CHtml::radioButtonList('Business[slider_type]', $model->slider_type, Business::getSliderTypeArray(), array(
                'template' => '<label class="radio">{input} {label}</label>'
            ));
            ?>
        </div>
    </div>
</form>

<script>
    $('.input-time').timepicker({
        showMeridian: true,
        defaultTime: false,
        showInputs: false
    });
</script>

<script>
    function copy_previous_day(i)
    {
        prev_day = (i - 1);
        id = '#Date_' + i;
        prev_id = '#Date_' + prev_day;

        copyDDLValue(prev_id + '_Morning_start', id + '_Morning_start');
        copyDDLValue(prev_id + '_Morning_end', id + '_Morning_end');

        copyDDLValue(prev_id + '_Afternoon_start', id + '_Afternoon_start');
        copyDDLValue(prev_id + '_Afternoon_end', id + '_Afternoon_end');

        copyDDLValue(prev_id + '_Evening_start', id + '_Evening_start');
        copyDDLValue(prev_id + '_Evening_end', id + '_Evening_end');

        $(id + '_checkbox').attr('checked', true);
        $(id + '_checkbox').parent('span').addClass('checked');
    }

    function copyDDLValue(fromId, toId) {
        from_value = $(fromId).val();
        ddl_to = $(toId).val(from_value);
    }
</script>
